<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品信息</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: inline-block;
            width: 100px;
            text-align: right;
            margin-right: 10px;
        }
        input[type="text"],
        input[type="number"],
        textarea,
        input[type="file"] {
            width: calc(100% - 120px);
            padding: 5px;
            box-sizing: border-box;
        }
        textarea {
            height: 150px;
        }
        .btn {
            display: block;
            margin: 20px auto;
            padding: 5px 10px;
            background-color: #f0f0f0;
            border: 1px solid #ccc;
            cursor: pointer;
        }
    </style>
</head>
<body>
<form id="goodsForm" enctype="multipart/form-data">
    <div class="form-group">
        <label for="productTitle">商品标题</label>
        <input type="text" id="productTitle" name="title" placeholder="请输入商品标题">
    </div>
    <div class="form-group">
        <label for="productPrice">商品价格</label>
        <input type="number" id="productPrice" name="price" placeholder="请输入商品价格">
    </div>
    <div class="form-group">
        <label for="productDescription">商品描述</label>
        <textarea id="productDescription" name="descr"></textarea>
    </div>
    <div class="form-group">
        <label for="productImage">商品图片</label>
        <input type="file" id="productImage" name="file">
    </div>
    <button type="submit" class="btn">保存</button>
</form>

<script>
    document.getElementById('goodsForm').addEventListener('submit', function(event) {
        event.preventDefault();
        var formData = new FormData(this);
        var mid = localStorage.getItem("mid");
        if (mid) {
            formData.append('mid', mid);
        } else {
            alert('请先登录以获取商家id');
            return;
        }
        fetch('/goods_func/up_goods', {
            method: 'POST',
            body: formData
        })
            .then(response => response.text())
            .then(message => {
                alert("新增商品成功");
            })
            .catch(error => {
                console.error('Error:', error);
                alert('商品添加失败');
            });
    });
</script>
</body>
</html>
